home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / falcon / programm.ing / nt_dsp1.lzh / NT_DSP1.MSA / MATRIX / MATMUL2.ASM < prev    next >
Assembly Source File  |  1989-01-24  |  3KB  |  77 lines

  1. ;
  2. ; This program originally available on the Motorola DSP bulletin board.
  3. ; It is provided under a DISCLAMER OF WARRANTY available from
  4. ; Motorola DSP Operation, 6501 Wm. Cannon Drive W., Austin, Tx., 78735.
  5. ; General Matrix Multiplication, C=AB. 
  6. ; Last Update 04 Feb 87   Version 1.0
  7. ;
  8.         opt     cex
  9.         page    132,66,0,0
  10. ;
  11. ;       matrix multiply. Implements X=AB matrix operation.
  12. ;
  13. ;       A 2x3
  14. mw      equ     2
  15. mx      equ     3
  16. ;       B 3x5
  17. my      equ     3
  18. mz      equ     5
  19. ;
  20. ;
  21. ;
  22.         org     x:0
  23. mat_a                           ; A matrix 2x3
  24.         dc        .4                    ;a(1,1)
  25.         dc        .3                    ;a(1,2)
  26.         dc        -.6                   ;a(1,3)
  27.         dc       .15                    ;a(2,1)
  28.         dc       -.8                    ;a(2,2)
  29.         dc       .25                    ;a(2,3)
  30.  
  31.         org     y:0
  32. mat_b                           ; B matrix 3x5
  33.         dc        -.4                   ;b(1,1)
  34.         dc        .35                   ;b(1,2)
  35.         dc       .15                    ;b(1,3)
  36.         dc        -.4                   ;b(1,4)
  37.         dc       .2                     ;b(1,5)
  38.         dc        .5                    ;b(2,1)
  39.         dc       -.3                    ;b(2,2)
  40.         dc       .4                     ;b(2,3)
  41.         dc        .1                    ;b(2,4)
  42.         dc       -.15                   ;b(2,5)
  43.         dc        .6                    ;b(3,1)
  44.         dc        -.35                  ;b(3,2)
  45.         dc       .45                    ;b(3,3)
  46.         dc        .25                   ;b(3,4)
  47.         dc        .2                    ;b(3,5)
  48.  
  49. mat_c   ds      mw*mz           ;output C martix 2x5
  50. ;
  51. ;       matrix multiply for row major storage format
  52. ;
  53.         org     p:$100
  54. matmul  move    #mat_a,r0       ;point to A matrix
  55.         move    #mat_b,r4       ;point to B matrix
  56.         move    #mat_c,r6       ;output to C matrix
  57.         move    #my,n0          ;second dimension of A
  58.         move    #mz,n5          ;second dimension of B
  59.  
  60.         do      #mw,_ew         ;number of final rows
  61.         do      #mz,_ez         ;number of final columns
  62.         move    r0,r1           ; copy ptr
  63.         move    r4,r5           ;copy second ptr
  64.         clr     a
  65.         move    x:(r1)+,x0  y:(r5)+n5,y0
  66.         rep     #my-1           ;inner sum
  67.         mac     x0,y0,a  x:(r1)+,x0  y:(r5)+n5,y0
  68.         macr    x0,y0,a   (r4)+ ;move to next column in B
  69.         move    a,y:(r6)+       ;save result
  70. _ez
  71.         move    (r0)+n0         ;move to next row in A
  72.         move    #mat_b,r4       ;point back to first column in B
  73. _ew
  74.         end
  75.